home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_023 / ver30 / tty / amigados / ttykbd.c < prev   
C/C++ Source or Header  |  1992-05-06  |  5KB  |  205 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *         Amiga virtual terminal keyboard, default console keymap.
  4.  * Version:    31
  5.  * Last edit:    20-Apr-86
  6.  * Created:    19-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  7.  *            Supports all the default console device
  8.  *            (RAW:) input codes for the Amiga keyboard.
  9.  * Modified:    20-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  10.  *        [UT-14A] Added processing for GR_to_META, so
  11.  *            characters in the alternate character set
  12.  *            can automatically map to META characters.
  13.  *            This is a rather nice thing to have...
  14.  */
  15. #include    "def.h"
  16.  
  17. #define    ESC    0x1B            /* Escape, arrows et al.    */
  18. #define    CSI    0x9B            /* Amiga CSI            */
  19.  
  20. /*
  21.  * The function keys on the Amiga send back
  22.  * escape sequences of the form <ESC>[code~, where code
  23.  * is a one or two-character code for the key.  To make
  24.  * it easier to decode, we place the internal key values
  25.  * for these codes in this table.
  26.  */
  27.  
  28. short    consolemap[] = {
  29.     KF1,        KF2,        KF3,        KF4,
  30.     KF5,        KF6,        KF7,        KF8,
  31.     KF9,        KF10,        KSF1,        KSF2,
  32.     KSF3,        KSF4,        KSF5,        KSF6,
  33.     KSF7,        KSF8,        KSF9,        KSF10
  34. };
  35. #define    NFUNCKEYS ((sizeof consolemap)/(sizeof consolemap[0]))
  36.  
  37. /*
  38.  * Names for the keys with basic keycode
  39.  * between KFIRST and KLAST (inclusive). This is used by
  40.  * the key name routine in "kbd.c".  KFIRST is KRANDOM, which
  41.  * we don't bind anything useful to.
  42.  */
  43. char    *keystrings[] = {
  44.     NULL,        "F1",        "F2",        "F3",
  45.     "F4",        "F5",        "F6",        "F7",
  46.     "F8",        "F9",        "F10",        "Shift-F1",
  47.     "Shift-F2",    "Shift-F3",    "Shift-F4",    "Shift-F5",
  48.     "Shift-F6",    "Shift-F7",    "Shift-F8",    "Shift-F9",
  49.     "Shift-F10",    "Up",        "Shift-Up",    "Down",
  50.     "Shift-Down",    "Left",        "Shift-Left",    "Right",
  51.     "Shift-Right",    "Help",        NULL,        NULL
  52. };
  53.  
  54. /*
  55.  * Read in a key, doing the low level mapping
  56.  * of ASCII code to 11 bit code. This level deals with
  57.  * mapping the special keys into their spots in the C1
  58.  * control area. The C0 controls go right through, and
  59.  * get remapped by "getkey".
  60.  *
  61.  * If GR_to_META is TRUE, characters in the Amiga alternate
  62.  * character set get mapped to META characters.  If FALSE,
  63.  * they get sent straight through.
  64.  */
  65.  
  66. #ifdef AS_DISTRIBUTED
  67. extern    int    GR_to_META;    /* defined in "kbd.c" */
  68. #else
  69. int    GR_to_META = TRUE;    /* not in *MY* "kbd.c"; Fred Fish */
  70. #endif
  71.  
  72. getkbd()
  73. {
  74.     register int    c;
  75.     register int    n;
  76. loop:
  77.     c = ttgetc();
  78.     if (c == CSI) {
  79.         c = ttgetc();
  80.         /* Unshifted arrow keys */
  81.         if (c == 'A')
  82.             return (KUP);
  83.         if (c == 'B')
  84.             return (KDOWN);
  85.         if (c == 'C')
  86.             return (KRIGHT);
  87.         if (c == 'D')
  88.             return (KLEFT);
  89.         if (c == 'T')
  90.             return (KSUP);
  91.         if (c == 'S')
  92.             return (KSDOWN);
  93.         if (c == '?') {
  94.             ttgetc();        /* discard '~' */
  95.             return (KHELP);
  96.         }
  97.  
  98.         /* Shifted left, right */
  99.         if (c == ' ') {
  100.             c = ttgetc();
  101.             if (c == 'A' || c == '@')
  102.                 return (c == 'A') ? (KSLEFT) : (KSRIGHT);
  103.             goto loop;        /* try again, sucker */
  104.         }
  105.  
  106.         /* Function keys    */
  107.         if (c >= '0' && c <= '9') {
  108.             n = 0;
  109.             do {
  110.                 n = 10*n + c - '0';
  111.                 c = ttgetc();
  112.             } while (c>='0' && c<='9');
  113.             if (c == '~' && n < NFUNCKEYS) {
  114.                 c = consolemap[n];
  115.                 if (c != KRANDOM)
  116.                     return (c);
  117.                 goto loop;
  118.             }
  119.             else 
  120.                 goto loop;    /* Try again */
  121.         }
  122.         goto loop;        /* Try again */
  123.     }
  124.  
  125.     /* Meta keys -- also check for high bit set */
  126.     if ((c == ESC) || (GR_to_META && (c & 0x80))) {
  127.         if (c == ESC)
  128.             c = ttgetc();
  129.         c &= 0x7F;            /* Strip high bit    */
  130.         if (ISLOWER(c) != FALSE)    /* Copy the standard    */
  131.             c = TOUPPER(c);        /* META code.        */
  132.         if (c>=0x00 && c<=0x1F)
  133.             c = KCTRL | (c+'@');
  134.         return (KMETA | c);
  135.     }
  136.     return (c);
  137. }
  138.  
  139. /*
  140.  * Terminal specific keymap initialization.
  141.  * Attach the special keys to the appropriate built
  142.  * in functions. Bind all of the assigned graphics in the
  143.  * Amiga alternate character set to self-insert.
  144.  * As is the case of all the keymap routines, errors
  145.  * are very fatal.
  146.  */
  147. ttykeymapinit()
  148. {
  149.     register SYMBOL    *sp;
  150.     register int    i;
  151.  
  152.     keydup(KUP,    "back-line");
  153.     keydup(KDOWN,    "forw-line");
  154.     keydup(KRIGHT,    "forw-char");
  155.     keydup(KLEFT,    "back-char");
  156.     keydup(KHELP,    "help");
  157.  
  158.     keydup(KSUP,    "goto-bob");
  159.     keydup(KSDOWN,    "goto-eob");
  160. #ifdef AS_DISTRIBUTED
  161.     keydup(KSRIGHT,    "goto-eop");
  162.     keydup(KSLEFT,    "goto-bop");
  163. #endif
  164.  
  165.     keydup(KF1,    "down-window");
  166.     keydup(KF2,    "forw-page");
  167.     keydup(KF3,    "enlarge-window");
  168.     keydup(KF4,    "forw-window");
  169.     keydup(KF5,    "split-window");
  170.     keydup(KF6,    "file-visit");
  171.     keydup(KF7,    "file-save");
  172.     keydup(KF8,    "start-macro");
  173.     keydup(KF9,    "bind-to-key");
  174.     keydup(KF10,    "display-version");
  175.  
  176.     keydup(KSF1,    "up-window");
  177.     keydup(KSF2,    "back-page");
  178.     keydup(KSF3,    "shrink-window");
  179.     keydup(KSF4,    "back-window");
  180.     keydup(KSF5,    "only-window");
  181.     keydup(KSF6,    "file-read");
  182.     keydup(KSF7,    "file-write");
  183.     keydup(KSF8,    "end-macro");
  184.     keydup(KSF9,    "display-bindings");
  185.     keydup(KSF10,    "quit");
  186.  
  187.     /*
  188.      * Bind all positions that correspond
  189.      * to characters in the Amiga alternate
  190.      * character set to "ins-self". These characters may
  191.      * be used just like any other character.
  192.      */
  193.  
  194.     if ((sp=symlookup("ins-self")) == NULL)
  195.         abort();
  196.     for (i=0xA0; i<0xFF; ++i) {
  197.         if (binding[i] != NULL)
  198.             abort();
  199.         binding[i] = sp;
  200.         ++sp->s_nkey;
  201.     }
  202. }
  203.  
  204.  
  205.